<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基本信息修改</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style>
        .discell {
            text-align:right;
            width:20%;
        }
        .input {
            width:30%;
        }
        .data-loading {
            position:absolute;
            width:100%;
            line-height:100px;
            display:none;
            text-align:center;
        }
    </style>
</head>
<body>
<div class="mini-fit" style="margin-bottom: 40px;">
    <form id="form1" method="post" style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <!-- 用户 编辑框START-->
        <div id="editform" class="form" style="padding:10px;">
            <input name="id" id="id" class="mini-hidden" style="width: 100%;" readonly />
            <input name="orgName" class="mini-hidden" style="width: 100%;" readonly />
            <input name="priNum" id="priNum" class="mini-hidden" style="width: 100%" readonly />
            <table class="form-table" align="center" style="width:85%" cellspacing="8">
                <tr>
                    <td style="font-weight: bold;text-align: center">基础信息:</td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>姓&emsp;&emsp;名:</td>
                    <td class="input">
                        <input name="pName" id="pName" class="mini-textbox" required="true" style="width: 80%;" />
                    </td>
                    <td class="discell">曾&nbsp;&nbsp;用&nbsp;&nbsp;名:</td>
                    <td class="input">
                        <input name="usedName" id="usedName" class="mini-textbox" value="无" style="width: 80%;" />
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>性&emsp;&emsp;别:</td>
                    <td class="input">
                        <input name="sex" id="sex" class="mini-combobox" required="true"
                               textField="codeName" valueField="codeId" emptyText="请选择..." style="width: 80%;"
                               url="/azbj/inmates/baseinfo/getTbsysCode?codeType=2_2&pcodeId=-1&sn=1"
                        />
                    </td>
                    <td class="discell"><font color="#dc143c">*</font>民&emsp;&emsp;族:</td>
                    <td>
                        <input name="nationality" id="nationality" class="mini-combobox" required="true"
                               textField="codeName" valueField="codeId" emptyText="请选择..." style="width: 80%;"
                               url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=2_4"
                        />
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>证件类型:</td>
                    <td>
                        <input name="idType" id="idType" class="mini-combobox" required="true" onvaluechanged="onIdTypeMouseOut()"
                               textField="codeName" valueField="codeId" emptyText="请选择..." style="width: 80%;"
                               url="/azbj/inmates/baseinfo/getTbsysCode?codeType=2_13&pcodeId=-1&sn=1"
                        />
                    </td>
                    <td class="discell"><font color="#dc143c" id="font">*</font>证件号码:</td>
                    <td>
                        <input name="idNum" id="idNum" class="mini-textbox"
                               onvaluechanged="onMouseOut()" required="true" emptyText="请填写证件号码" style="width: 80%;" />
                    </td>
                </tr>
                <tr>
                    <td><input class="mini-hidden" name="num" id="num"></td>
                </tr>
                <tr>
                    <td class="discell">出生日期:</td>
                    <td class="input">
                        <input property="editor" class="mini-datepicker" id="age" name="age" allowInput="false" style="width: 80%;" ondrawdate="onDrawDate"/>
                    </td>
                    <td class="discell"><font color="#dc143c">*</font>
                        <#if level=="05">
                            入矫日期:
                        <#else >
                            入监日期:
                        </#if>
                    </td>
                    <td class="input">
                        <input property="editor" class="mini-datepicker" id="addtime" name="addtime" allowInput="false" required="true"
                               style="width: 80%;" ondrawdate="onDrawDate"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>文化程度:</td>
                    <td>
                        <input name="education" id="education" class="mini-combobox"
                               textField="codeName" valueField="codeId" emptyText="请选择..." style="width: 80%;"
                               url="/azbj/inmates/baseinfo/getTbsysCode?codeType=2_5&pcodeId=0&sn=0" required="true"
                        />
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <hr />
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold;text-align: center">户籍信息:</td>
                </tr>
                <tr>
                    <td class="discell"></td>
                    <td class="input">
                        <input name="hjType" id="hjType" class="mini-radiobuttonlist"
                               data="[{ id: ''+'01', name: '户籍完整人员' },{ id: ''+'02', name: '查不清户籍人员' }]"
                               textField="name" valueField="id" value="01" required="true" showNullItem="true"
                               onvaluechanged="hjTypeOnclick()" />
                    </td>
                </tr>
                <tr id="hjlx">
                    <td class="discell"><font color="#dc143c">*</font>户籍类型:</td>
                    <td colspan="3">
                        <input name="priAddr" id="priAddr" class="mini-radiobuttonlist"
                               data="[{ id: ''+'01', name: '农村户籍' },{ id: ''+'02', name: '城镇户籍' }<#--,{ id: ''+'03', name: '户籍为监所' }-->,{ id: ''+'04', name: '非大陆籍' }]"
                               textField="name" valueField="id" value="01" required="true" showNullItem="true"
                               onvaluechanged="hjOnclick()" />
                    </td>
                </tr>
            </table>
        </div>

        <!-- 户籍信息-->
        <div id="wzhjry" class="form" style="padding:10px;">
            <table class="form-table" align="center" style="width:85%" cellspacing="8">
                <tr>
                    <td style="width: 20%;text-align: right"><font color="#dc143c">*</font>
                        户籍地址:
                    </td>
                    <td colspan="3" style="width: 80%">
                        <input id="nativepro" name="nativepro" class="mini-combobox" required="true" emptyText="省份"
                               style="width:22%;"
                               textfield="codeName" valueField="codeId"
                               onclick="onDeptChanged('nativepro')" onvaluechanged="onValueChanged('nativepro')" />
                        <input id="nativecity" name="nativecity" class="mini-combobox" required="true" emptyText="市"
                               style="width: 23%"
                               textfield="codeName" valueField="codeId" onclick="onDeptChanged('nativecity')"
                               onvaluechanged="onValueChanged('nativecity')" />
                        <input id="nativecou" name="nativecou" class="mini-combobox" required="true" emptyText="县"
                               style="width: 23%"
                               textfield="codeName" valueField="codeId" onclick="onDeptChanged('nativecou')"
                               onvaluechanged="onValueChanged('nativecou')" />
                        <input id="nativevill" name="nativevill" class="mini-combobox" emptyText="街道" style="width:23%"
                               textfield="codeName" valueField="codeId"onclick="onDeptChanged('nativevill')" showNullItem="true" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;text-align: right"></td>
                    <td colspan="3" style="width: 80%">
                        <input class="mini-textbox" required="true" style="width: 92.5%" emptyText="详细地址" id="nativenum"
                               name="nativenum" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;text-align: right">
                        <#if "${localCode !''}"=='140000'>
                            日常居住地:
                        <#else>
                            居住地址:
                        </#if>
                    </td>
                    <td colspan="3" style="width: 80%">
                        <input id="placepro" name="placepro" class="mini-combobox" emptyText="省份" style="width:22%;"
                               textfield="codeName" valueField="codeId"
                               onclick="onLiveChanged('placepro')" onvaluechanged="onChanged('placepro')" />
                        <input id="placecity" name="placecity" class="mini-combobox" emptyText="市" style="width: 23%"
                               textfield="codeName" valueField="codeId" onclick="onLiveChanged('placecity')"
                               onvaluechanged="onChanged('placecity')" />
                        <input id="placecou" name="placecou" class="mini-combobox" emptyText="县" style="width: 23%"
                               textfield="codeName" valueField="codeId" onclick="onLiveChanged('placecou')"
                               onvaluechanged="onChanged('placecou')" />
                        <input id="placevill" name="placevill" class="mini-combobox" emptyText="街道" style="width: 23%" showNullItem="true"
                               textfield="codeName" valueField="codeId"onclick="onLiveChanged('placevill')" />

                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;text-align: right"></td>
                    <td colspan="3" style="width: 80%">
                        <input class="mini-textbox" style="width: 92.5%" emptyText="详细地址" id="placenum" name="placenum" />
                    </td>
                </tr>
            </table>
        </div>

        <#--查不清户籍人员-->
        <div id="cbqhj" class="form" style="padding:10px;display: none">
            <table class="form-table" align="center" style="margin-left: 10%;margin-right: 10%" cellspacing="8">
                <tr>
                    <td style="width: 20%;text-align: right"><font color="#dc143c">*</font>
                        户籍地址:
                    </td>
                    <td colspan="3" style="width: 80%">
                        户籍地址不明
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;text-align: right">
                        <font color="#dc143c">*</font>原侦查机关所在地:
                    </td>
                    <td colspan="3" style="width: 80%">
                        <input id="investigatePro" name="investigatePro" class="mini-combobox" emptyText="省份" style="width:22%;"
                               textfield="codeName" valueField="codeId" required="true"
                               onclick="onNoLiveChanged('investigatePro')" onvaluechanged="onNoChanged('investigatePro')" />
                        <input id="investigateCity" name="investigateCity" class="mini-combobox" emptyText="市" style="width: 23%"
                               textfield="codeName" valueField="codeId" onclick="onNoLiveChanged('investigateCity')"
                               required="true"
                               onvaluechanged="onNoChanged('investigateCity')" />
                        <input id="investigateCou" name="investigateCou" class="mini-combobox" emptyText="县" style="width: 23%"
                               textfield="codeName" valueField="codeId" onclick="onNoLiveChanged('investigateCou')"
                               required="true"
                               onvaluechanged="onNoChanged('investigateCou')" />
                        <input id="investigateVill" name="investigateVill" class="mini-combobox" emptyText="街道" style="width: 23%"
                               required="true"
                               textfield="codeName" valueField="codeId"onclick="onNoLiveChanged('investigateVill')" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;text-align: right"></td>
                    <td colspan="3" style="width: 80%">
                        <input class="mini-textbox" style="width: 92.5%" emptyText="详细地址" id="investigateNum" name="investigateNum"
                               required="true" />
                    </td>
                </tr>
            </table>
        </div>
        <!-- 非大陆籍 -->
        <div id="fdlj" class="form" style="padding:10px;display: none">
            <table class="form-table" align="center" style="margin-left: 10%;margin-right: 10%" cellspacing="8">
                <tr>
                    <td style="width: 20%;text-align: right">
                        <font color="#dc143c">*</font>具体类型:
                    </td>
                    <td colspan="3" style="width: 80%;">
                        <input name="detailType" id="detailType" class="mini-combobox" value="${detailType!''}"
                               data="[{ id: 1, name: '外国籍' },{ id: 2, name: '无国籍' },{ id: 3, name: '香港' },{ id: 4, name: '澳门' },{ id: 5, name: '台湾' }]"
                               textField="name" valueField="id" value="1" required="true" showNullItem="false" /><#--onvaluechanged="jsOnclick()"-->
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;text-align: right">
                        <font color="#dc143c">*</font>逮捕机构:
                    </td>
                    <td colspan="3" style="width: 80%">
                        <input id="arrestpro" name="arrestpro" class="mini-combobox" required="true" emptyText="省份"
                               style="width:22%;"
                               textfield="codeName" valueField="codeId"
                               onclick="onDBLiveChanged('arrestpro')" onvaluechanged="onDBChanged('arrestpro')" />
                        <input id="arrestcity" name="arrestcity" class="mini-combobox" required="true" emptyText="市"
                               style="width: 23%"
                               textfield="codeName" valueField="codeId" onclick="onDBLiveChanged('arrestcity')"
                               onvaluechanged="onDBChanged('arrestcity')" />
                        <input id="arrestcou" name="arrestcou" class="mini-combobox" required="true" emptyText="县"
                               style="width: 23%"
                               textfield="codeName" valueField="codeId" onclick="onDBLiveChanged('arrestcou')"
                               onvaluechanged="onDBChanged('arrestcou')" />
                        <input id="arrestvill" name="arrestvill" class="mini-combobox" emptyText="街道" style="width: 23%"
                               textfield="codeName" valueField="codeId"onclick="onDBLiveChanged('arrestvill')" required="true" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 20%;text-align: right"></td>
                    <td colspan="3" style="width: 80%">
                        <input class="mini-textbox" required="true" style="width: 92.5%" emptyText="详细地址" name="arrestnum"
                               id="arrestnum" />
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
<div style="position: absolute;bottom: 0;line-height:40px;width: 100%;border-top:1px solid #dfdfdf;text-align: center">
    <a class="mini-button" iconCls="fa-save" plain="true" style="font-size: 15px " onclick="saveData()">保存</a>
</div>

<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var name = mini.get("pName").getValue();
    var id = mini.get("id");
    var priNum = mini.get("priNum");
    var idNum = mini.get("idNum");
    var idType = mini.get("idType");
    var nativepro = mini.get("nativepro");
    var nativecity = mini.get("nativecity");
    var nativecou = mini.get("nativecou");
    var nativevill = mini.get("nativevill");
    var nativenum = mini.get("nativenum");
    var placepro = mini.get("placepro");
    var placecity = mini.get("placecity");
    var placecou = mini.get("placecou");
    var placevill = mini.get("placevill");
    var placenum = mini.get("placenum");

    var arrestpro = mini.get("arrestpro");
    var arrestcity = mini.get("arrestcity");
    var arrestcou = mini.get("arrestcou");
    var arrestvill = mini.get("arrestvill");
    var arrestnum = mini.get("arrestnum");
    var investigatePro = mini.get("investigatePro");
    var investigateCity = mini.get("investigateCity");
    var investigateCou = mini.get("investigateCou");
    var investigateVill = mini.get("investigateVill");
    var investigateNum = mini.get("investigateNum");
    var age = mini.get("age");
    var addtime = mini.get("addtime");
    var successFlag = ${successFlag!"0"};

    function saveData() {
        console.log(age.getValue());
        //校验系统中是否存在该身份证的预安置人员
        var mark = true;
        //编辑页面
        if (mini.get("idNum").getValue() != '') {
            var priNum1 = "-1";
            var priNum11 =  mini.get("priNum").getValue();
            if(priNum11 != "undefined" && priNum11 != null && priNum11 != "") {
                priNum1 = priNum11;
            }
            $.ajax({
                url: "/azbj/inmates/checkIdNumUpdate/" + priNum1 + "/" + mini.get("idNum").getValue(),
                cache: false,
                async: false,
                success: function (success) {
                    if (success.code != 1) {
                        mark = false;
                    }
                }
            });
            $.ajax({
                url: "/azbj/inmates/findPrisonerByIdNum?idNum=" + idNum.getValue(),
                type: 'GET',
                async: false,
                datatype: 'json',
                success: function (data) {
                    if (data === 'FUXING_EXISTS') {
                        mini.alert("该服刑人员未出狱,请勿重复添加");
                        return;
                    }
                }
            });
        }
        if (!mark && null == priNum) {
            mini.confirm("系统中已经存在该身份证号的预安置人员,确定继续添加？",
                "确定添加？",
                function (action) {
                    if (action == "ok") {
                        if (idType.getValue() == "1" || idType.getValue() == "2") { //当证件类型为身份证号或者临时身份证号时才进行校验
                             if (!onIDCardsValidation(idNum.getValue())) {
                                mini.alert("请输入正确的身份证号");
                                return;
                            }
                        }
                        //校验出生日期和入监日期，出生日期不能在入监日期之后
                        if (age.getValue() != "" && addtime.getValue() != "") {
                            if (age.getValue() > addtime.getValue()) {
                                mini.alert("入监日期应该大于出生日期");
                                return;
                            }
                        }

                        form.validate();
                        if (form.isValid() == false) {
                            return;
                        }
                        var data = form.getData();
                        var json = mini.encode(data);

                        mini.mask({
                            el: document.body,
                            cls: 'mini-mask-loading',
                            html: '加载中...'
                        });
                        $.ajax({
                            url: "/azbj/inmates/baseinfo/save",
                            data: {data: json},
                            type: "post",
                            success: function (success) {
                                mini.unmask(document.body);
                                if (success.code == 1) {
                                    var idstr = success.data.id;
                                    var priNumstr = success.data.priNum;
                                    priNum.setValue(priNumstr);
                                    id.setValue(idstr);
                                    mini.alert("保存成功");
                                } else if (success.code = 5599) {
                                    mini.alert(success.message);
                                } else {
                                    mini.alert("保存失败");
                                }
                            }, error: function () {
                                mini.unmask(document.body);
                                mini.alert("系统异常");
                            }
                        })
                    }
                });
        } else {
            //当证件类型为身份证号或者临时身份证号时才进行校验
            if (idType.getValue() == "1" || idType.getValue() == "2") {
                if (!onIDCardsValidation(idNum.getValue())) {
                    mini.alert("请输入正确的身份证号");
                    return;
                }
            }

            //校验出生日期和入监日期，出生日期不能在入监日期之后
            if (age.getValue() != "" && addtime.getValue() != "") {
                if (age.getValue() > addtime.getValue()) {
                    mini.alert("入监日期应该大于出生日期");
                    return;
                }
            }

            form.validate();
            if (form.isValid() == false) {
                return;
            }
            var data = form.getData();
            //在保存时 根据选中的状态只保存一个信息
            var hjValue = mini.get("hjType").getValue();
            var priValue  = mini.get("priAddr").getValue();
            //户籍完整并且农村 将其他置为空
            if (hjValue == '01' && priValue == '01'){
                //将原侦查机关、逮捕机构、城镇置为空
                data.investigatePro = '';
                data.investigateCity = '';
                data.investigateCou = '';
                data.investigateVill = '';
                data.investigateNum = '';
                data.arrestpro = '';
                data.arrestcity = '';
                data.arrestcou = '';
                data.arrestvill = '';
                data.arrestnum = '';
                // 少一个城镇的id什么的
            }else if (hjValue == "01" && priValue == '02') {
                //户籍完整城镇户籍 将原侦查机关、逮捕机构、农村置为空
                data.investigatePro = '';
                data.investigateCity = '';
                data.investigateCou = '';
                data.investigateVill = '';
                data.investigateNum = '';
                data.arrestpro = '';
                data.arrestcity = '';
                data.arrestcou = '';
                data.arrestvill = '';
                data.arrestnum = '';
                //农村的id
            }else if (hjValue == "01" && priValue == "04" ) {
                //户籍完整非大陆籍 将原侦查机关、农村城镇置为空
                data.investigatePro = '';
                data.investigateCity = '';
                data.investigateCou = '';
                data.investigateVill = '';
                data.investigateNum = '';
                data.nativepro = '';
                data.nativecity = '';
                data.nativecou = '';
                data.nativevill = '';
                data.nativenum = '';
                data.placepro = '';
                data.placecity = '';
                data.placecou = '';
                data.placevill = '';
                data.placenum = '';
            }else if (hjValue == '02') {
                //查不清户籍 将农村城镇、逮捕机构置为空
                data.nativepro = '';
                data.nativecity = '';
                data.nativecou = '';
                data.nativevill = '';
                data.nativenum = '';
                data.placepro = '';
                data.placecity = '';
                data.placecou = '';
                data.placevill = '';
                data.placenum = '';
                data.arrestpro = '';
                data.arrestcity = '';
                data.arrestcou = '';
                data.arrestvill = '';
                data.arrestnum = '';
            }

            var json = mini.encode(data);

            mini.mask({
                el: document.body,
                cls: 'mini-mask-loading',
                html: '加载中...'
            });
            $.ajax({
                url: "/azbj/inmates/baseinfo/save",
                data: {data: json},
                type: "post",
                success: function (success) {
                    mini.unmask(document.body);
                    if (success.code == 1) {
                        var idstr = success.data.id;
                        var priNumstr = success.data.priNum;
                        priNum.setValue(priNumstr);
                        id.setValue(idstr);
                        mini.alert("保存成功");
                    } else if (success.code = 5599) {
                        mini.alert(success.message);
                    } else {
                        mini.alert("保存失败");
                    }
                }, error: function () {
                    mini.unmask(document.body);
                    mini.alert("系统异常");
                }
            })
        }
    }
    //点击农村、城镇、非大陆籍
    function hjOnclick() {
        var value = mini.get("priAddr").getValue();
        if (value == "02") {
            // 城镇户籍
            document.getElementById("wzhjry").style.display = "block";
            document.getElementById("fdlj").style.display = "none";
            document.getElementById("cbqhj").style.display = "none";
            mini.get("nativevill").setValue('');
        } else if (value == "04") {
            //非大陆籍
            document.getElementById("wzhjry").style.display = "none";
            document.getElementById("fdlj").style.display = "block";
            document.getElementById("cbqhj").style.display = "none";
        } else {
            //农村户籍
            document.getElementById("wzhjry").style.display = "block";
            document.getElementById("fdlj").style.display = "none";
            document.getElementById("cbqhj").style.display = "none";
        }
    }

    /**
     * 查不清户籍 与 户籍完整人员大类显示控制方法
     */
    function hjTypeOnclick() {
        var value = mini.get("hjType").getValue();
        var priAddrValue = mini.get("priAddr").getValue();
        if (value == "02") { //查不清户籍人员
            document.getElementById("wzhjry").style.display = "none";
            document.getElementById("fdlj").style.display = "none";
            document.getElementById("hjlx").style.display = "none";
            document.getElementById("cbqhj").style.display = "block";
        } else {
            if (priAddrValue == "04") {//非大陆籍
                document.getElementById("wzhjry").style.display = "none";
                document.getElementById("hjlx").style.display = "";
                document.getElementById("fdlj").style.display = "block";
                document.getElementById("cbqhj").style.display = "none";
            } else {
                document.getElementById("wzhjry").style.display = "block";
                document.getElementById("hjlx").style.display = "";
                document.getElementById("fdlj").style.display = "none";
                document.getElementById("cbqhj").style.display = "none";
            }
        }
    }

    /**
     * 户籍地址
     * @param e
     */
    //点击
    var urltemp = "/azbj/getCodeDetail/?codeType=2_1&codeId=-2";
    function onDeptChanged(e) {
        // placepro placecity  placecou placevill
        if ("nativepro" == e) {
            var value = nativepro.getValue();
            nativepro.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=-1";
            nativepro.setUrl(url);
            if (value != '') {
                nativepro.setValue(value);
            } else {
                nativepro.select(0);
            }
        }
        if ("nativecity" == e) {
            var value = nativecity.getValue();
            if (nativepro.getValue() == "") {
                nativepro.setUrl(urltemp);
                nativepro.setValue("");
                nativecou.setUrl(urltemp);
                nativecou.setValue("");
                nativevill.setUrl(urltemp);
                nativevill.setValue("");
                return;
            }
            var codeId = nativepro.getValue();
            nativecity.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            nativecity.setUrl(url);
            if (value != '') {
                nativecity.setValue(value);
            } else {
                nativecity.select(0);
            }
        }

        if ("nativecou" == e) {
            var value = nativecou.getValue();
            if (nativecity.getValue() == "") {
                nativecou.setUrl(urltemp);
                nativecou.setValue("");
                nativevill.setUrl(urltemp);
                nativevill.setValue("");
                return;
            }
            var codeId = nativecity.getValue();
            nativecou.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            nativecou.setUrl(url);
            if (value != '') {
                nativecou.setValue(value);
            } else {
                nativecou.select(0);
            }
        }

        if ("nativevill" == e) {
            var value = nativevill.getValue();

            if (nativecou.getValue() == "") {
                nativevill.setUrl(urltemp);
                nativevill.setValue("");
                return;
            }
            var parent_code = nativecou.getValue();
            nativevill.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            nativevill.setUrl(url);
            if (value != '') {
                nativevill.setValue(value);
            } else {
                nativevill.select(0);
            }
        }
    }

    function onValueChanged(e) {
        if ("nativepro" == e) {
            nativecity.setValue("");
            nativecou.setValue("");
            nativevill.setValue("");
        }

        if ("nativecity" == e) {
            nativecou.setValue("");
            nativevill.setValue("");
        }

        if ("nativecou" == e) {
            nativevill.setValue("");
        }

    }

    /**
     * 居住地址
     * placepro  placecity placecou placevill placenum
     * @param e
     */
    function onLiveChanged(e) {
        if ("placepro" == e) {
            var value = placepro.getValue();
            placepro.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=-1";
            placepro.setUrl(url);
            if (value != '') {
                placepro.setValue(value);
            } else {
                placepro.select(0);
            }
        }
        if ("placecity" == e) {
            var value = placecity.getValue();

            if (placepro.getValue() == "") {
                placepro.setUrl(urltemp);
                placepro.setValue("");
                placecou.setUrl(urltemp);
                placecou.setValue("");
                placevill.setUrl(urltemp);
                placevill.setValue("");
                return;
            }
            var codeId = placepro.getValue();
            placecity.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            placecity.setUrl(url);
            if (value != '') {
                placecity.setValue(value);
            } else {
                placecity.select(0);
            }
        }

        if ("placecou" == e) {
            var value = placecou.getValue();

            if (placecity.getValue() == "") {
                placecou.setUrl(urltemp);
                placecou.setValue("");
                placevill.setUrl(urltemp);
                placevill.setValue("");
                return;
            }
            var codeId = placecity.getValue();
            placecou.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            placecou.setUrl(url);
            if (value != '') {
                placecou.setValue(value);
            } else {
                placecou.select(0);
            }
        }

        if ("placevill" == e) {
            var value = placevill.getValue();

            if (placecou.getValue() == "") {
                placevill.setUrl(urltemp);
                placevill.setValue("");
                return;
            }
            var parent_code = placecou.getValue();
            placevill.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            placevill.setUrl(url);
            if (value != '') {
                placevill.setValue(value);
            } else {
                placevill.select(0);
            }
        }
    }

    function onChanged(e) {
        if ("placepro" == e) {
            placecity.setValue("");
            placecou.setValue("");
            placevill.setValue("");
        }
        if ("placecity" == e) {
            placecou.setValue("");
            placevill.setValue("");

        }
        if ("placecou" == e) {
            placevill.setValue("");
        }
    }

    /**
     * 监所地址
     * @param e
     */
    function onJsDeptChanged(e) {
        if ("prisonspro" == e) {
            var value = prisonspro.getValue();
            prisonspro.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=-1";
            prisonspro.setUrl(url);
            if (value != '') {
                prisonspro.setValue(value);
            } else {
                prisonspro.select(0);
            }
        }
        if ("prisonscity" == e) {
            var value = prisonscity.getValue();

            if (prisonspro.getValue() == "") {
                prisonspro.setUrl(urltemp);
                prisonspro.setValue("");
                prisonscou.setUrl(urltemp);
                prisonscou.setValue("");
                prisonsvill.setUrl(urltemp);
                prisonsvill.setValue("");
                return;
            }
            var codeId = prisonspro.getValue();
            prisonscity.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            prisonscity.setUrl(url);
            if (value != '') {
                prisonscity.setValue(value);
            } else {
                prisonscity.select(0);
            }
        }

        if ("prisonscou" == e) {
            var value = prisonscou.getValue();

            if (prisonscity.getValue() == "") {
                prisonscou.setUrl(urltemp);
                prisonscou.setValue("");
                prisonsvill.setUrl(urltemp);
                prisonsvill.setValue("");
                return;
            }
            var codeId = prisonscity.getValue();
            prisonscou.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            prisonscou.setUrl(url);
            if (value != '') {
                prisonscou.setValue(value);
            } else {
                prisonscou.select(0);
            }
        }

        if ("prisonsvill" == e) {
            var value = prisonsvill.getValue();

            if (prisonscou.getValue() == "") {
                prisonsvill.setUrl(urltemp);
                prisonsvill.setValue("");
                return;
            }
            var parent_code = prisonscou.getValue();
            prisonsvill.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            prisonsvill.setUrl(url);
            if (value != '') {
                prisonsvill.setValue(value);
            } else {
                prisonsvill.select(0);
            }
        }
    }

    function onJSValueChanged(e) {
        if ("prisonspro" == e) {
            prisonscity.setValue("");
            prisonscou.setValue("");
            prisonsvill.setValue("");
        }

        if ("prisonscity" == e) {
            prisonscou.setValue("");
            prisonsvill.setValue("");
        }

        if ("prisonscou" == e) {
            prisonsvill.setValue("");
        }
    }


    /**
     * 逮捕地址
     * arrestpro  arrestcity arrestcou arrestvill
     * @param e
     */
    function onDBLiveChanged(e) {
        if ("arrestpro" == e) {
            var value = arrestpro.getValue();
            arrestpro.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=-1";
            arrestpro.setUrl(url);
            if (value != '') {
                arrestpro.setValue(value);
            } else {
                arrestpro.select(0);
            }
        }
        if ("arrestcity" == e) {
            var value = arrestcity.getValue();
            if (arrestpro.getValue() == "") {
                arrestpro.setUrl(urltemp);
                arrestpro.setValue("");
                arrestcou.setUrl(urltemp);
                arrestcou.setValue("");
                arrestvill.setUrl(urltemp);
                arrestvill.setValue("");
                return;
            }
            var codeId = arrestpro.getValue();
            arrestcity.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            arrestcity.setUrl(url);
            if (value != '') {
                arrestcity.setValue(value);
            } else {
                arrestcity.select(0);
            }
        }

        if ("arrestcou" == e) {
            var value = arrestcou.getValue();

            if (arrestcity.getValue() == "") {
                arrestcou.setUrl(urltemp);
                arrestcou.setValue("");
                arrestvill.setUrl(urltemp);
                arrestvill.setValue("");
                return;
            }
            var codeId = arrestcity.getValue();
            arrestcou.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            arrestcou.setUrl(url);
            if (value != '') {
                arrestcou.setValue(value);
            } else {
                arrestcou.select(0);
            }
        }

        if ("arrestvill" == e) {
            var value = arrestvill.getValue();

            if (arrestcou.getValue() == "") {
                arrestvill.setUrl(urltemp);
                arrestvill.setValue("");
                return;
            }
            var parent_code = arrestcou.getValue();
            arrestvill.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            arrestvill.setUrl(url);
            if (value != '') {
                arrestvill.setValue(value);
            } else {
                arrestvill.select(0);
            }
        }
    }

    function onDBChanged(e) {
        if ("arrestpro" == e) {
            arrestcity.setValue("");
            arrestcou.setValue("");
            arrestvill.setValue("");
        }
        if ("arrestcity" == e) {
            arrestcou.setValue("");
            arrestvill.setValue("");
        }
        if ("arrestcou" == e) {
            arrestvill.setValue("");
        }
    }

    window.onload = function () {
        var data = parent.setChildValue();
        priNum.setValue(data.priNum);
        SetData(priNum.getValue());
        if (successFlag == 1 && (data.priNum.search('A') != '-1' || data.priNum.search('B') != '-1')) {
            nativevill.setRequired(true);
        }
        var idType = mini.get("idType");
        var idNum = mini.get("idNum");
        if (idType.getValue() === '98') {
            idNum.setValue('');
            idNum.setEnabled(false);
            idNum.setEmptyText("无证件号码，不用填写");
            $("#font").hide();
            idNum.required = false;
            $("#idNum").addClass("mini-textbox-disabled mini-textbox-readOnly");
        }
    }

    function SetData(data) {
        if (data) {
            mini.get("id").setEnabled(false);
        }
        // 根据ID去数据库中查询数据
        $.ajax({
            url: "/azbj/inmates/getbaseinfo?prinum=" + data,
            type: "post",
            async:false,
            dataType: "json",
            success: function (bsdata) {
                form.setData(bsdata);
                form.setChanged(false);
                nativepro.setData([{codeId: bsdata.nativepro, codeName: bsdata.nativeproName}]);
                nativecity.setData([{codeId: bsdata.nativecity, codeName: bsdata.nativecityName}]);
                nativecou.setData([{codeId: bsdata.nativecou, codeName: bsdata.nativecouName}]);
                nativevill.setData([{codeId: bsdata.nativevill, codeName: bsdata.nativevillName}]);
                placepro.setData([{codeId: bsdata.placepro, codeName: bsdata.placeproName}]);
                placecity.setData([{codeId: bsdata.placecity, codeName: bsdata.placecityName}]);
                placecou.setData([{codeId: bsdata.placecou, codeName: bsdata.placecouName}]);
                placevill.setData([{codeId: bsdata.placevill, codeName: bsdata.placevillName}]);

                arrestpro.setData([{codeId: bsdata.arrestpro, codeName: bsdata.arrestproName}]);
                arrestcity.setData([{codeId: bsdata.arrestcity, codeName: bsdata.arrestcityName}]);
                arrestcou.setData([{codeId: bsdata.arrestcou, codeName: bsdata.arrestcouName}]);
                arrestvill.setData([{codeId: bsdata.arrestvill, codeName: bsdata.arrestvillName}]);
                investigatePro.setData([{codeId: bsdata.investigatePro, codeName: bsdata.investigateProName}]);
                investigateCity.setData([{codeId: bsdata.investigateCity, codeName: bsdata.investigateCityName}]);
                investigateCou.setData([{codeId: bsdata.investigateCou, codeName: bsdata.investigateCouName}]);
                investigateVill.setData([{codeId: bsdata.investigateVill, codeName: bsdata.investigateVillName}]);
                if (bsdata.hjType == '02') {
                    // hjTypeOnclick;
                    hjTypeOnclick();
                } else {
                    // hjOnclick();
                    var value = bsdata.priAddr;
                    if (value == "02") { // 城镇户籍
                        document.getElementById("wzhjry").style.display = "block";
                        document.getElementById("fdlj").style.display = "none";
                        document.getElementById("cbqhj").style.display = "none";
                     } else if (value == "04") {
                        document.getElementById("wzhjry").style.display = "none";
                        document.getElementById("fdlj").style.display = "block";
                        document.getElementById("cbqhj").style.display = "none";
                    } else {//农村户籍
                        document.getElementById("wzhjry").style.display = "block";
                        document.getElementById("fdlj").style.display = "none";
                        document.getElementById("cbqhj").style.display = "none";
                    }
                }
            }
        });
    }

    /**
     * 查不清户籍人员地址
     */
    function onNoLiveChanged(e) {
        if ("investigatePro" == e) {
            var value = investigatePro.getValue();
            investigatePro.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=-1";
            investigatePro.setUrl(url);
            if (value != '') {
                investigatePro.setValue(value);
            } else {
                investigatePro.select(0);
            }
        }
        if ("investigateCity" == e) {
            var value = investigateCity.getValue();
            if (investigatePro.getValue() == "") {
                investigatePro.setUrl(urltemp);
                investigatePro.setValue("");
                investigateCou.setUrl(urltemp);
                investigateCou.setValue("");
                investigateVill.setUrl(urltemp);
                investigateVill.setValue("");
                return;
            }
            var codeId = investigatePro.getValue();
            investigateCity.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            investigateCity.setUrl(url);
            if (value != '') {
                investigateCity.setValue(value);
            } else {
                investigateCity.select(0);
            }
        }

        if ("investigateCou" == e) {
            var value = investigateCou.getValue();
            if (investigateCity.getValue() == "") {
                investigateCou.setUrl(urltemp);
                investigateCou.setValue("");
                investigateVill.setUrl(urltemp);
                investigateVill.setValue("");
                return;
            }
            var codeId = investigateCity.getValue();
            investigateCou.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            investigateCou.setUrl(url);
            if (value != '') {
                investigateCou.setValue(value);
            } else {
                investigateCou.select(0);
            }
        }

        if ("investigateVill" == e) {
            var value = investigateVill.getValue();
            if (investigateCou.getValue() == "") {
                investigateVill.setUrl(urltemp);
                investigateVill.setValue("");
                return;
            }
            var parent_code = investigateCou.getValue();
            investigateVill.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            investigateVill.setUrl(url);
            if (value != '') {
                investigateVill.setValue(value);
            } else {
                investigateVill.select(0);
            }
        }
    }

    function onNoChanged(e) {
        if ("investigatePro" == e) {
            investigateCity.setValue("");
            investigateCou.setValue("");
            investigateVill.setValue("");
        }
        if ("investigateCity" == e) {
            investigateCou.setValue("");
            investigateVill.setValue("");
        }
        if ("investigateCou" == e) {
            investigateVill.setValue("");
        }
    }

    function onMouseOut() {
        var id = mini.get("idNum").getValue();
        if (id !== "") {
            //当证件类型为身份证号或者临时身份证号时才进行校验
            if (idType.getValue() == "1" || idType.getValue() == "2") {
                if (onIDCardsValidation(idNum.getValue())) {
                    //获取到用户的身份证号码|临时身份证号码
                    var age = id.substring(6, 10) + "-" + id.substring(10, 12) + "-" + id.substring(12, 14);
                    mini.get("age").setValue(age);
                    var num = id[16];
                    if(num%2 ==0){
                        mini.get("sex").setValue("2");
                    } else {
                        mini.get("sex").setValue("1");
                    }
                } else if (id.length == 15 && onIDCardsValidation(idNum.getValue())) {
                    var num = id[14];
                    if(num%2 ==0){
                        mini.get("sex").setValue("2");
                    } else {
                        mini.get("sex").setValue("1");
                    }
                } else {
                    mini.alert("请输入正确的身份证号码");
                }
            }
        }
    }

    function onIdTypeMouseOut() {
        var idType = mini.get("idType");
        var idNum = mini.get("idNum");
        var num = mini.get("num");
        //如果证件类型选择'无'
        if (idType.getValue() === '98') {
            idNum.setEmptyText("无证件号码，不用填写");
            $("#font").hide();
            idNum.required = false;
            $("#idNum").toggleClass("mini-textbox-disabled mini-textbox-readOnly");
            idNum.setEnabled(false);
            num.setValue(idNum.getValue());
            idNum.setValue('无');
        } else {
            //如果证件类型选择其他
            if (idNum.getValue() === '' && (num.getValue() !== '' || num.getValue() !== null)) {
                idNum.setValue(num.getValue());
            }
            idNum.setEmptyText("请填写证件号码");
            idNum.setEnabled(true);
            $("#font").show();
            idNum.required = true;
        }
        var id = mini.get("idNum").getValue();
        if (idType.getValue() == "1" || idType.getValue() == "2") { //当证件类型为身份证号或者临时身份证号时才进行校验
            if (idNum.getValue() != "") {
                if (onIDCardsValidation(idNum.getValue())) {
                    var age = id.substring(6, 10) + "-" + id.substring(10, 12) + "-" + id.substring(12, 14);
                    mini.get("age").setValue(age);
                    var num = id[16];
                    if(num%2 ==0){
                        mini.get("sex").setValue("2");
                    } else {
                        mini.get("sex").setValue("1");
                    }
                } else if (id.length == 15 && onIDCardsValidation(idNum.getValue())) {
                    var num = id[14];
                    if(num%2 ==0){
                        mini.get("sex").setValue("2");
                    } else {
                        mini.get("sex").setValue("1");
                    }
                } else {
                    mini.alert("请输入正确的身份证号码");
                }
            }
        }
    }

    /**
     * 禁止选择今天之后的日期
     * @param e
     */
    function onDrawDate(e) {
        var date = e.date;
        var d = new Date();
        if (date.getTime() > d.getTime()) {
            e.allowSelect = false;
        }
    }
</script>
</body>
</html>